<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('路段列表')"/>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=YPeaoO6MQGjDhoGcy99f1t1uKHMtwVoc"> </script>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                                    <li>
                                        <label>归属高速：</label>
                                        <select name="fkId"
                                                th:with="type=${@dict.getType('gsgs')}">
                                            <option value="">所有</option>
                                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                    th:value="${dict.dictValue}"></option>
                                        </select>
                                    </li>
                                    <li>
                                        <label>管养单位：</label>
                                        <select name="muId"
                                                th:with="type=${@dict.getType('gydw')}">
                                            <option value="">所有</option>
                                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                                    th:value="${dict.dictValue}"></option>
                                        </select>
                                    </li>
                                    <li>
                                        <label>路段：</label>
                                        <input type="text" name="sectionName"/>
                                    </li>
                                    <li class="select-time">
                                        <label>数据日期：</label>
                                        <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                               name="params[beginDataTime]"/>
                                        <span>-</span>
                                        <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                               name="params[endDataTime]"/>
                                    </li>
                                    <li>
                                        <label>路段：</label>
                                        <input type="text" name="sectionName"/>
                                    </li>
                                    <li>
                                        <label>编号：</label>
                                        <input type="text" name="sectionId"/>
                                    </li>
                                    <li>
                                        <label>起点：</label>
                                        <input type="text" name="startName"/>
                                    </li>
                                    <li>
                                        <label>终点：</label>
                                        <input type="text" name="endName"/>
                                    </li>
                                    <li>
                                        <label>起始桩号：</label>
                                        <input type="text" name="startPileNumber"/>
                                    </li>
                                    <li>
                                        <label>结束桩号：</label>
                                        <input type="text" name="endPileNumber"/>
                                    </li>
                                    <li class="select-time">
                                        <label>通车时间：</label>
                                        <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                               name="params[beginUseTime]"/>
                                        <span>-</span>
                                        <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                               name="params[endUseTime]"/>
                                    </li>
                                    <li>
                                        <label>序列号：</label>
                                        <input type="text" name="serialNumber"/>
                                    </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="road:road_section:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="road:road_section:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="road:road_section:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="road:road_section:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-info " onclick="initRoadPile()" shiro:hasPermission="road:road_section:insertByRoadStatke">
                <i class="fa fa-tags"></i> 初始化路桩
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="road:road_section:export">
                <i class="fa fa-download"></i> 数据归档
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="road:road_section:export">
                <i class="fa fa-download"></i> 数据备份
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
        <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content animated bounceInRight">
                    <div class="modal-body">
                        <div id="allmap2" style="width: 100%;height: 500px;"></div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onclick="" title="点击确认，重新计算该路段经纬度" data-dismiss="modal">确认</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('road:road_section:edit')}]];
    var removeFlag = [[${@permission.hasPermi('road:road_section:remove')}]];
    var testFlag = [[${@permission.hasPermi('road:road_section:displayMap')}]];
    var fkIdDatas = [[${@dict.getType('gsgs')}]];
    var muIdDatas = [[${@dict.getType('gydw')}]];
    var prefix = ctx + "road/road_section";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "路段",
            columns: [{
                checkbox: true
            },
                        {
                            field: 'id',
                            title: '主键',
                            visible: false
                        },
                        // {
                        //     field: 'sectionName',
                        //     title: '归属高速',
                        //     formatter: function (value, row, index) {
                        //         return $.table.selectDictLabel(fkIdDatas, value);
                        //     }
                        // },
                        // {
                        //     field: 'muId',
                        //     title: '管养单位',
                        //     formatter: function (value, row, index) {
                        //         return $.table.selectDictLabel(muIdDatas, value);
                        //     }
                        // },
                        // {
                        //     field: 'remark',
                        //     title: '备注'
                        // },
                        // {
                        //     field: 'sectionName',
                        //     title: '路段'
                        // },
                        // {
                        //     field: 'dataTime',
                        //     title: '数据日期'
                        // },
                        {

                            field: 'sectionName',
                            title: '路段'
                        },
                        {

                            field: 'sectionId',
                            title: '编号'
                        },
                        {
                            field: 'startName',
                            title: '起点'
                        },
                        {
                            field: 'endName',
                            title: '终点'
                        },
                        {
                            field: 'startPileNumber',
                            title: '起始桩号'
                        },
                        {
                            field: 'endPileNumber',
                            title: '结束桩号'
                        },
                        {
                            field: 'useTime',
                            title: '通车时间'
                        },
                        {
                            field: 'serialNumber',
                            title: '序列号'
                        },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>路桩管理</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>车道维护</a>');
                        actions.push('<a class="fa fa-map-marker" data-toggle="modal" data-target="#myModal"  onclick="displaymap(\'' + row.id + '\')"><i></i>地图查看</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
<script>
    function displaymap(id){
        $.get('/road/road_section/displayMap/'+id,function (result){
            initmap(result)
        })
    }
    initmap=function (result){
        var map = new BMap.Map("allmap2");
        var centerLongitude=(result.startLongitude+result.endLongitude)/2
        var centerLatitude=(result.startLatitude+result.endLatitude)/2
        map.centerAndZoom(new BMap.Point(centerLongitude, centerLatitude), 11);
        var p1 = new BMap.Point(result.startLongitude,result.startLatitude);
        var p2 = new BMap.Point(result.endLongitude,result.endLatitude);

        var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
        driving.search(p1, p2);
    }
</script>
<!--路桩初始化-->
<script>
    function initRoadPile(){
        var firstColumn=$.table.selectFirstColumns();
        if (firstColumn.length==0){
            $.modal.alert('请选取路段初始化！')
            return;
        }
        var sectionName = $.table.selectColumns("sectionName");
        var sectionId = $.table.selectColumns("id");
        console.log(sectionId)
        $.modal.confirm('初始化<div style="color: red;">'+sectionName+'</div>路段！！！',function (){
            $.post('/road/road_section/selectRoadSectionStateById/'+sectionId,function (result){
                alert(result.code)
                if (result.code==500){
                    layer.msg('该路段已经初始化完成！',{
                        time: 2000 //0.5秒关闭（如果不配置，默认是3秒）
                    });
                }
                if (result.code==301){
                    layer.msg("请重新选择",{
                        time: 3000 //0.5秒关闭（如果不配置，默认是3秒）
                    });
                }
                if (result.code==0) {
                    $.modal.loading("初始化中，请稍等！")
                    $.post('/road/road_section/modifyRoadSectionState/'+sectionId,function (result){
                        if (result.code==0){
                            $.post('/road/road_stake/insertByRoadStake/'+sectionId,function (result){
                                if (result.code==0){
                                    $.modal.closeLoading();
                                    alert("初始化成功！")
                                    layer.msg("初始化成功！",{
                                        time: 2000 //0.5秒关闭（如果不配置，默认是3秒）
                                    });

                                }
                                if (result.code==500){
                                    $.modal.closeLoading();
                                    $.modal.loading("初始化失败！")
                                    alert("初始化失败！！")
                                    layer.msg("初始化失败！",{
                                        time: 2000 //0.5秒关闭（如果不配置，默认是3秒）
                                    });
                                }
                            })
                        }
                        if (result.code==500){
                            $.modal.closeLoading();
                            $.modal.loading("初始化失败！")
                            layer.msg("初始化失败！",{
                                time: 2000 //0.5秒关闭（如果不配置，默认是3秒）
                            });
                        }

                    })
                }
            })

        })
    }
</script>
</body>
</html>
